package com.mangofactory.aop.configuration.tag
{
	import com.mangofactory.aop.configuration.AspectContainerBuilder;
	import com.mangofactory.aop.configuration.MetatagProxyPolicy;

	[DefaultProperty("proxyDefinitions")]
	public class AbstractAspectSupportTag
	{
		private var proxyRegistry:MetatagProxyPolicy = new MetatagProxyPolicy();
		private var _aspectContainerBuilder:AspectContainerBuilder;
		
		private var _tagProcessors:Array = [new MetatagPolicyTagProcessor(),new MethodPolicyTagProcessor()]
		public function AbstractAspectSupportTag()
		{
			_aspectContainerBuilder = new AspectContainerBuilder();
		}
		
		private var _proxyDefinitions:Array;

		public function get tagProcessors():Array
		{
			return _tagProcessors;
		}

		public function set tagProcessors(value:Array):void
		{
			_tagProcessors = value;
			processTags();
		}

		[ArrayElementType("com.mangofactory.aop.configuration.tag.PolicyProviderTag")]
		public function get proxyDefinitions():Array
		{
			return _proxyDefinitions;
		}
		
		public function set proxyDefinitions(value:Array):void
		{
			_proxyDefinitions = value;
			processTags();
		}
		
		private function processTags():void
		{
			if (!proxyDefinitions || !tagProcessors)
				return;
			
			for each (var policyTag:PolicyProviderTag in proxyDefinitions)
			{
				for each (var tagProcessor:PolicyTagProcessor in tagProcessors)
				{
					if (tagProcessor.isForTag(policyTag))
					{
						tagProcessor.processTag(policyTag,aspectContainerBuilder);
						continue;
					}
				}
			}
		}
		protected function get aspectContainerBuilder():AspectContainerBuilder
		{
			return _aspectContainerBuilder;
		}

	}
}